// pages/Main/mainIndex/mainIndex.js
var VideobusinessLogic = require('../../../utils/NetWork/Model/VideobusinessLogic.js')
var BookbusinessLogic = require('../../../utils/NetWork/Model/BookbusinessLogic.js')
var common = require('../../../utils/common.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 1

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = common.Getorgid();
    var scrollHeight = scrollHeight;
    wx.getSystemInfo({
      success: function (res) {
        scrollHeight = res.windowHeight
      }
    });
    this.setData({
      orgid: c.orgid,
      userid: c.userid,
      scrollHeight: scrollHeight,
    });
    this.BookCollection();
  },
  teacher: function () {
    wx.navigateTo({
      url: "../teacherOrder/teacherOrder"
    });
  },
  parents: function () {
    wx.navigateTo({
      url: "../post/post"
    });
  },
  student: function () {
    wx.navigateTo({
      url: "../post/post"
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  isSelect: function (e) {
    this.setData({
      isSelect: !this.data.isSelect
    })
  }, vdetail: function (e) {
    var id = e.currentTarget.dataset.videoid
    wx.navigateTo({
      url: '../../Video/videoDetail/videoDetail?id=' + id,
    })
  }, bdetail: function (e) {
    var id = e.currentTarget.dataset.bookid
    wx.navigateTo({
      url: '../../Book/bookDetail/bookDetail?id=' + id,
    })
  },
  bindDownLoad: function () {
    if (this.data.lenpage > this.data.num) {
      var di = this.data.num;
      var di = di + 1;
      this.setData({
        num: di
      });
      this.BookCollection();
    } else {
      common.showToast("加载全部", "loading");
    }
    //common.showToast("到底了", "loading");

  },
   BookCollection: function () {
     common.showToast("加载中", "loading");
    // this.setData({ isSelect: !this.data.isSelect })
     let params = { "page": this.data.num, "num": 10, orgid: this.data.orgid, userid: this.data.userid, searchField: "peopleid,iscollect", searchValue: this.data.userid + ",1 " }
    //console.log(params)
    BookbusinessLogic.BookCollection(params, (res) => {
      //console.log(res)
      var page = res.page
      var res = res.infos;
      //第五步 把获取的值，传入data
      var bbb = []
      for (var a = 0; a < res.length; a++) {
        bbb.push(res[a]);
      }

      //第五步 把获取的值，传入data
      this.setData({
        bookList: bbb,
        lenpage: page.pages
      });
      common.hideLoading();
    });
  },
  QueryVideoCollectionList: function () {
    common.showToast("加载中", "loading");
    this.setData({ isSelect: !this.data.isSelect })
    let params = { "page": this.data.num, "num": 10, orgid: this.data.orgid, userid: this.data.userid, searchField: "peopleid,iscollect", searchValue: this.data.userid + ",1 " }
    //console.log(params)
    VideobusinessLogic.QueryVideoCollectionList(params, (res) => {
      // console.log(res)
      for (var i = 0; i < res.length; i++) {
        if (res[i].videoid_video_onclick > 999999) {
          res[i].videoid_video_onclick = 999999 + "+";
        } else {
          res[i].videoid_video_onclick = res[i].videoid_video_onclick + "次";
        }
      }
      //第五步 把获取的值，传入data
      var page = res.page
      var res = res.infos;
      //第五步 把获取的值，传入data
      var aaa = []
      for (var a = 0; a < res.length; a++) {
        aaa.push(res[a]);
      }
      this.setData({
        videoList:aaa,
        lenpage: page.pages
      });
    });
  },
})